// Copyright (c) 2022 NetEase, Inc. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

package com.netease.yunxin.kit.conversationkit.ui.fun.viewholder;

import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;

import com.compass.framework.utils.LogUtil;
import com.google.gson.Gson;
import com.netease.yunxin.kit.common.ui.utils.AvatarColor;
import com.netease.yunxin.kit.conversationkit.ui.databinding.FunConversationViewHolderBinding;
import com.netease.yunxin.kit.conversationkit.ui.model.ConversationBean;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 会话列表数据设置
 */
public class FunConversationP2PViewHolder extends FunConversationBaseViewHolder {

    public FunConversationP2PViewHolder(@NonNull FunConversationViewHolderBinding binding) {
        super(binding);
    }

    @Override
    public void onBindData(ConversationBean data, int position) {
        super.onBindData(data, position);
        String name = data.infoData.getName();
        viewBinding.avatarView.setData(
                data.infoData.getAvatar(),
                data.infoData.getAvatarName(),
                AvatarColor.avatarColor(data.infoData.getContactId()));
        viewBinding.nameTv.setText(name);

        //设置医生type
        String extend = data.infoData.getUserInfo().getExtension();
        if (!TextUtils.isEmpty(extend)) {
            JSONObject jsonObject = null;
            try {
                jsonObject = new JSONObject(extend);
                String userType = jsonObject.getString("userType");
                //userType 1医生 2护师 3药师
                if (userType.equals("1")) {
                    viewBinding.tvDoctor.setVisibility(View.VISIBLE);
                    viewBinding.tvDoctor.setText("医生");
                } else if (userType.equals("2")) {
                    viewBinding.tvDoctor.setVisibility(View.VISIBLE);
                    viewBinding.tvDoctor.setText("护师");
                } else if (userType.equals("3")) {
                    viewBinding.tvDoctor.setVisibility(View.VISIBLE);
                    viewBinding.tvDoctor.setText("药师");
                } else {
                    viewBinding.tvDoctor.setVisibility(View.GONE);
                }
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        } else {
            //设置医生标识
            viewBinding.tvDoctor.setVisibility(View.GONE);
        }


    }
}
